<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      selectionType="single"
      :columns="columns"
      :fetchapi="fetchApi"
      :rowstyles="rowstyles"
      :onSyncTableData="syncPjFun"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
    </FilterTable>

    <Drawer
      :visible.sync="visibleDrawer"
      title="配件索赔单审批"
      width="80vw"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-modal v-model="initData" @close="infoClose" />
    </Drawer>

    <BaseDialog
      :visible.sync="issearch"
      :title="'经销商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>

    <Drawer
      :visible.sync="showDetailFlag"
      title="配件索赔单明细"
      width="80vw"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-detail v-model="initData" @close="infoClose" />
    </Drawer>
  </div>
</template>
  
<script>
import infoDetail from '../query/info';
import infoModal from './info';
import ownerSeacher from './ownerSeacher';
import { dictionary } from '@/utils/dictMixin';
import { getClaimData } from '@/api/partsmanage/claim/apply';
export default {
  name: 'chaimapproveindex',
  mixins: [dictionary],
  components: {
    infoModal,
    ownerSeacher,
    infoDetail
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns(),
      fetchApi: getClaimData,
      tableData: [],
      visibleDrawer: false,
      rowstyles: [],
      initData: {},
      dealerCode:'',
      issearch:false,
      showDetailFlag: false,
    }
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '索赔单号:',
          fieldName: 'spddhm'
        },
        {
          type: 'INPUT',
          label: '采购单号',
          fieldName: 'student_age'
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          },
          change:p=>{
            if(!p){
              this.dealerCode=''
            }
          }
        },
        {
          type: 'SELECT',
          label: '索赔类型:',
          fieldName: 'bssplx',
          placeholder: '请选择...',
          itemList: this.createDictList('5006')
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.detailHandle(props.row, 'edit')}>
                  审核
                </multiuse-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.showDetail(props.row,'show')}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'dealer_code',
          sorter: true,
          // width: 120
        },
        {
          title: '经销商名称',
          dataIndex: 'dealer_name',
          sorter: true,
          // width: 160
        },
        {
          title: '索赔单号',
          dataIndex: 'spddhm',
          sorter: true,
          // width: 160
        },
        {
          title: '是否超期',
          dataIndex: 'sfcq',
          sorter: true,
          // width: 100
        },
        {
          title: '索赔类型',
          dataIndex: 'bssplx',
          sorter: true,
          // width: 100,
          render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.bssplx, '5006')}</span>;
          }
        },
        {
          title: '索赔状态',
          dataIndex: 'xsddzt',
          sorter: true,
          // width: 100,
          render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.xsddzt, '5007')}</span>;
          }
        },
        {
          title: '索赔数量',
          dataIndex: 'sppjsl',
          sorter: true,
          // width: 100
        },
        {
          title: '索赔金额',
          dataIndex: 'bsspze',
          sorter: true,
          // width: 100
        },
        {
          title: '采购单号',
          dataIndex: 'cgddhm',
          sorter: true,
          width: 160
        },
        {
          title: '提报日期',
          dataIndex: 'bstjsj',
          sorter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          width: 150
        },
        {
          title: '操作时间',
          dataIndex: 'updated_at',
          sorter: true,
          width: 120,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          width: 150
        },
        // {
        //   title: '索赔种类',
        //   dataIndex: 'sppjzl',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '经办人',
        //   dataIndex: 'xtczry',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '创建日期',
        //   dataIndex: 'created_at',
        //   sorter: true,
        //   filter: true,
        //   dateFormat: 'yyyy-MM-dd hh:mm:ss',
        //   showOverflowTooltip: true,
        //   filterType: 'date-range'
        // }
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xsddzt: '50071002',cxlx: 'approve', xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    detailHandle(row,type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.showDetailFlag = false;
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    dealercloseHandler(val){
      if(val){
        this.topFilterList.find(x=>x.fieldName=='dealerName').initialValue=val.dealerName;
        this.fetchParams=Object.assign({
          dealerCode: val.dealerCode
        },this.fetchParams)
        this.dealerCode=val.dealerCode
      }
      this.issearch=false;
    },
    seacherFun(){
      this.issearch=true;
    },
    syncPjFun(details, isOverdue){
      if (!details.length) return;
      details.forEach(x => {
        if (x.sfcq == '已超期') {
          // console.log(x,"x")
          this.rowstyles.push({ row: x, styles: { background: '#FF0000' } });
        }
      });
    },
    showDetail(row,type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.showDetailFlag = true;
    }
  }
}
</script>